/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bt;

/**
 *
 * @author Mathieu
 */
 public class ClientThread
    extends Thread
    {
        // Search type
        private int searchType;

        /** Constructor
         * @param st The search type. Possible values:
         * {@link BluetoothDiscovery.SEARCH_CONNECT_FIRST_FOUND SEARCH_CONNECT_FIRST_FOUND},
         * {@link BluetoothDiscovery.SEARCH_CONNECT_ALL_FOUND SEARCH_CONNECT_ALL_FOUND},
         * {@link BluetoothDiscovery.SEARCH_ALL_DEVICES_SELECT_ONE SEARCH_ALL_DEVICES_SELECT_ONE},
         * {@link BluetoothDiscovery.SEARCH_ALL_DEVICES_SELECT_SEVERAL SEARCH_ALL_DEVICES_SELECT_SEVERAL}.
         */
        protected ClientThread( int st)
        {
            // store search type
            searchType = st;
        }


        /**
         * This method runs the client.
         */
        public void run()
        {
            try
            {
                BluetoothConnection conn[] = Main.disc.searchService( searchType );
                if( conn.length != 0 )
                {   // Create Canvas object which deals with receive and send
                    nc = new NumberCanvas( conn );
                    // Set as new display
                    display.setCurrent( nc );
                }
                else
                {   // nothing found
                    startUI();
                }
            }
            catch( Exception e )
            {    // display error message
                showAlertAndExit( "Error:", e.getMessage(), AlertType.ERROR );
                return;
            }
        }
    }
